package com.cy.myblog.model;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

@Entity
@Table(name = "tcomment")
public class Tcomment implements Serializable{

	/**
	 * 评论留言
	 */
	private static final long serialVersionUID = 5275701465875296589L;

	private String id;
	private String cmmauthor;
	private String cmmcontent;
	private Tarticle article;
	private Set<Tcomment> comments;
	private Tcomment comment;
	private Integer support;
	private Date cmmtime;
	
	public Tcomment() {
		super();
	}
	
	public Tcomment(String id, String cmmauthor, String cmmcontent,
			Tarticle article, Set<Tcomment> comments, Tcomment comment,
			Integer support, Date cmmtime) {
		super();
		this.id = id;
		this.cmmauthor = cmmauthor;
		this.cmmcontent = cmmcontent;
		this.article = article;
		this.comments = comments;
		this.comment = comment;
		this.support = support;
		this.cmmtime = cmmtime;
	}


	@Id
	@Column(name = "id", unique = true, nullable = false, length = 38)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getCmmauthor() {
		return cmmauthor;
	}
	public void setCmmauthor(String cmmauthor) {
		this.cmmauthor = cmmauthor;
	}
	public String getCmmcontent() {
		return cmmcontent;
	}
	public void setCmmcontent(String cmmcontent) {
		this.cmmcontent = cmmcontent;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "articleid")
	public Tarticle getArticle() {
		return article;
	}
	public void setArticle(Tarticle article) {
		this.article = article;
	}
	
	@OneToMany(mappedBy = "comment")
	@LazyCollection(LazyCollectionOption.EXTRA)
	public Set<Tcomment> getComments() {
		return comments;
	}
	public void setComments(Set<Tcomment> comments) {
		this.comments = comments;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "cmmpid")
	public Tcomment getComment() {
		return comment;
	}
	public void setComment(Tcomment comment) {
		this.comment = comment;
	}
	public Integer getSupport() {
		return support;
	}
	public void setSupport(Integer support) {
		this.support = support;
	}
	public Date getCmmtime() {
		return cmmtime;
	}
	public void setCmmtime(Date cmmtime) {
		this.cmmtime = cmmtime;
	}
}
